#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
const int maxn = 4;
int n = 4, m = 4;
char G[maxn][maxn] = {  //平面图 矩形 默认行为n 列为m
        'A', 'B', 'C', 'D',
        'E', 'F', 'G', 'H',
        'I', 'J', 'K', 'L',
        'M', 'N', 'O', 'P'
};
int book[maxn][maxn];
int fx[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};//四连通 顺时针方向
void dfs(int x, int y) {
    cout << G[x][y] << " ";
    book[x][y] = 1;
    for (int i = 0; i < 4; i++) {
        int nx = x + fx[i][0];//相邻的四连通点的x新坐标
        int ny = y + fx[i][1];//相邻的四连通点的y新坐标
        if (nx < 0 || nx >= n || ny < 0 || ny >= m)continue; //检查位置的有效性
        if (book[nx][ny] == 1)continue;//避免重复访问
        dfs(nx, ny);
    }
}

int main() {

    dfs(0, 0);
    return 0;
}
